﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SQLite;
using System.Diagnostics; // Process Class
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
using Microsoft.Windows.Controls.Ribbon;
using SleuthKit;

namespace AFT2
{
    public partial class MainWindow : RibbonWindow
    {
        public enum LIST_TYPE { None, PhoneBookList, CallList, SmsList, MmsList, 
            CalendarList, BookmarkList, SearchList, MapSearchList, GPSList,
            WifiList, FacebookFriendsList, KakaotalkFriendsList, SeoulbusList,
            FacebookPhotoList, FacebookNotificationList, KakaotalkChatroomsList,
            KakaotalkChatlogList
            
        };
        [Serializable]
        public class CurrentInformation
        {
            public DeviceInformationLoader deviceInformation;
            public ApplicationLoader.KaKaoTalk kakaoTalkLoader;
            public ApplicationLoader.Facebook facebookLoader;
            public ApplicationLoader.SeoulBus seoulBusLoader;
            public ApplicationLoader.MapSearchHistory mapSearchHistoryLoader;
            public ApplicationLoader.GPSHistory gpsHistory;
            public MMSDataList mmsList;
            public PhoneBookDataList phoneList;
            public CalendarDataList calendarList;
            public BookMarksDataList bookmarkList;
            public SearchesDataList searchDataList;
            public SMSDataList smsList;
            public CallDataList callList;        
            
        }
        public LIST_TYPE curListType;
        public StackPanel filterCheckBoxChildrenPanel;
        public Dictionary<string, bool> filterCheckList;
        CurrentInformation currentInfo;

        public MainWindow()
        {
            InitializeComponent();
            new splashDemo.SplashWindow().ShowDialog();
            currentInfo = new CurrentInformation();
            curListType = LIST_TYPE.None;                            

            // 리본탭 선택 이벤트 핸들러 추가
            Ribbon.SelectionChanged += new SelectionChangedEventHandler(Ribbon_SelectionChanged);
            DataGrid_User.MouseDoubleClick += new MouseButtonEventHandler(DatagridUser_DoubleClick);

            // 어플리게이션메뉴-보조패널 수정
            //Ribbon.ApplicationMenu.AuxiliaryPaneContent = str;
            //testNak();
            //fileOpen("c:\\log.txt");
            //offsetBox.Clear();
        }

        /*
         * 리본탭 선택 이벤트 핸들러
         */
        private void Ribbon_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // 각 리본탭마다 보여줄 메인 그리드를 바꿔줌
            switch (Ribbon.SelectedIndex)
            {
                case 0:
                    {
                        Grid_Device.Visibility = System.Windows.Visibility.Visible;
                        Grid_User.Visibility = System.Windows.Visibility.Collapsed;
                        Grid_System.Visibility = System.Windows.Visibility.Collapsed;
                        Grid_Memory.Visibility = System.Windows.Visibility.Collapsed;
                    }
                    break;
                case 1:
                    {
                        Grid_Device.Visibility = System.Windows.Visibility.Collapsed;
                        Grid_User.Visibility = System.Windows.Visibility.Visible;
                        Grid_System.Visibility = System.Windows.Visibility.Collapsed;
                        Grid_Memory.Visibility = System.Windows.Visibility.Collapsed;
                    }
                    break;
                case 2:
                    {
                        Grid_Device.Visibility = System.Windows.Visibility.Collapsed;
                        Grid_User.Visibility = System.Windows.Visibility.Collapsed;
                        Grid_System.Visibility = System.Windows.Visibility.Visible;
                        Grid_Memory.Visibility = System.Windows.Visibility.Collapsed;
                    }
                    break;
                case 3:
                    {
                        Grid_Device.Visibility = System.Windows.Visibility.Collapsed;
                        Grid_User.Visibility = System.Windows.Visibility.Collapsed;
                        Grid_System.Visibility = System.Windows.Visibility.Collapsed;
                        Grid_Memory.Visibility = System.Windows.Visibility.Visible;
                    }
                    break;
            }
        }

        /*
         * 버튼 이벤트 핸들러
         */
        private void RibbonButton_SMS(object sender, RoutedEventArgs e)
        {
            DataGrid_User.ItemsSource = currentInfo.smsList.data;
            curListType = LIST_TYPE.SmsList;
            MakeFilter();
        }
        private void RibbonButton_Web(object sender, RoutedEventArgs e)
        {
            DataGrid_User.ItemsSource = currentInfo.bookmarkList.data;
            curListType = LIST_TYPE.BookmarkList;
            MakeFilter();
        }
        private void RibbonButton_MMS(object sender, RoutedEventArgs e)
        {
            DataGrid_User.ItemsSource = currentInfo.mmsList.data;
            curListType = LIST_TYPE.MmsList;
            MakeFilter();
        }
        private void RibbonButton_Calls(object sender, RoutedEventArgs e)
        {
            DataGrid_User.ItemsSource = currentInfo.callList.data;
            curListType = LIST_TYPE.CallList;
            MakeFilter();
        }
        private void RibbonButton_Contacts(object sender, RoutedEventArgs e)
        {
            DataGrid_User.ItemsSource = currentInfo.phoneList.data;
            curListType = LIST_TYPE.PhoneBookList;
            MakeFilter();
        }
        private void RibbonButton_Calendar(object sender, RoutedEventArgs e)
        {
            DataGrid_User.ItemsSource = currentInfo.calendarList.data;
            curListType = LIST_TYPE.CalendarList;
            MakeFilter();
        }
        private void RibbonButton_SearchLog(object sender, RoutedEventArgs e)
        {
            DataGrid_User.ItemsSource = currentInfo.searchDataList.data;
            curListType = LIST_TYPE.SearchList;
            MakeFilter();
        }
        private void RibbonButton_MapSearchLog(object sender, RoutedEventArgs e)
        {
            DataGrid_User.ItemsSource = currentInfo.mapSearchHistoryLoader.searchList.ToList();
            curListType = LIST_TYPE.MapSearchList;
            MakeFilter();
        }
        private void RibbonButton_Wifi(object sender, RoutedEventArgs e)
        {
            DataGrid_User.ItemsSource = currentInfo.deviceInformation.wifiInformation.wifiHistoryList.ToList();
            curListType = LIST_TYPE.WifiList;
            MakeFilter();
        }
        private void RibbonButton_disPackage(object sender, RoutedEventArgs e)
        {
            DataGrid_System.ItemsSource = currentInfo.deviceInformation.disabledPackages.disabledPackages;
        }

        private void RibbonButton_enPackage(object sender, RoutedEventArgs e)
        {
            DataGrid_System.ItemsSource = currentInfo.deviceInformation.enabledPackages.enabledPackages;
        }

        private void RibbonButton_sysPackage(object sender, RoutedEventArgs e)
        {
            DataGrid_User.ItemsSource = currentInfo.deviceInformation.systemPackages.systemPackages;
        }

        private void RibbonButton_tpPackage(object sender, RoutedEventArgs e)
        {
            DataGrid_System.ItemsSource = currentInfo.deviceInformation.thirdPartyPackages.thirdpartyPackages;
        }

        private void RibbonButton_allPackage(object sender, RoutedEventArgs e)
        {
            DataGrid_System.ItemsSource = currentInfo.deviceInformation.allPackages.allPackages;
        }

        private void RibbonButton_Disk(object sender, RoutedEventArgs e)
        {
            DataGrid_System.ItemsSource = currentInfo.deviceInformation.diskInformation.diskInfomation;
        }

        private void RibbonButton_Proc(object sender, RoutedEventArgs e)
        {
            DataGrid_System.ItemsSource = currentInfo.deviceInformation.processInformation.processInformation;
        }

        private void RibbonButton_Netstat(object sender, RoutedEventArgs e)
        {
            DataGrid_System.ItemsSource = currentInfo.deviceInformation.networkState.networkstateinformation;
        }

        private void RibbonButton_NetCfg(object sender, RoutedEventArgs e)
        {
            DataGrid_System.ItemsSource = currentInfo.deviceInformation.networkCfg.netcfginformation;
        }

        private void RibbonButton_Facebook(object sender, RoutedEventArgs e)
        {
            DataGrid_User.ItemsSource = currentInfo.facebookLoader.friendsList.ToList();
            curListType = LIST_TYPE.FacebookFriendsList;
            MakeFilter();
        }

        private void RibbonButton_Kakao(object sender, RoutedEventArgs e)
        {
            DataGrid_User.ItemsSource = currentInfo.kakaoTalkLoader.friendsList;
            curListType = LIST_TYPE.KakaotalkFriendsList;
            MakeFilter();
        }

        private void RibbonButton_SeoulBus(object sender, RoutedEventArgs e)
        {
            DataGrid_User.ItemsSource = currentInfo.seoulBusLoader.recentBusList.ToList();
            curListType = LIST_TYPE.SeoulbusList;
            MakeFilter();
        }

        private void RibbonButton_FacebookPhotos(object sender, RoutedEventArgs e)
        {
            DataGrid_User.ItemsSource = currentInfo.facebookLoader.photosList;
            curListType = LIST_TYPE.FacebookPhotoList;
            MakeFilter();
        }

        private void RibbonButton_FacebookNotification(object sender, RoutedEventArgs e)
        {
            DataGrid_User.ItemsSource = currentInfo.facebookLoader.notificationsList;
            curListType = LIST_TYPE.FacebookNotificationList;
            MakeFilter();
        }

        private void RibbonButton_KakaoRoom(object sender, RoutedEventArgs e)
        {
            DataGrid_User.ItemsSource = currentInfo.kakaoTalkLoader.chatRoomsList;
            curListType = LIST_TYPE.KakaotalkChatroomsList;
            MakeFilter();
        }

        private void RibbonButton_GPS(object sender, RoutedEventArgs e)
        {
            DataGrid_User.ItemsSource = currentInfo.gpsHistory.gpsList;
            curListType = LIST_TYPE.GPSList;
            MakeFilter();
        }

        private void RibbonButton_WifiLastAp(object sender, RoutedEventArgs e)
        {
            DataGrid_User.ItemsSource = currentInfo.deviceInformation.wifiInformation.wifiLastAP;
        }

        void DataGrid_Memory_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }
        private void RibbonButton_getDisk(object sender, RoutedEventArgs e)
        {
            ProgressDialogResult result = ProgressDialog.Execute(this, "Loading data", (bw) =>
            {
                for (int i = 1; i <= 3; i++)
                {
                    switch (i)
                    {
                        case 1:
                            ProgressDialog.Report(bw, "추출할 디스크를 확인하는 중입니다..", i);
                            Process process = new Process();
                            process.StartInfo.FileName = "adb.exe";
                            process.StartInfo.UseShellExecute = false;
                            //process.StartInfo.RedirectStandardOutput = true;
                            process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
                            process.StartInfo.CreateNoWindow = true;
                            process.EnableRaisingEvents = true;
                            process.StartInfo.Arguments = " shell dd if=/dev/block/mmcblk0p13 of=/sdcard/13.img";
                            process.Exited += new EventHandler(exit_fileExact);
                            process.Start();
                            while (!flag)
                            {
                                System.Threading.Thread.Sleep(500);
                            }
                            flag = false;

                            process = new Process();
                            process.StartInfo.FileName = "adb.exe";
                            process.StartInfo.UseShellExecute = false;
                            //process.StartInfo.RedirectStandardOutput = true;
                            process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
                            process.StartInfo.CreateNoWindow = true;
                            process.EnableRaisingEvents = true;
                            process.StartInfo.Arguments = "shell dd if=/dev/block/mmcblk0p17 of=/sdcard/17.img";
                            process.Exited += new EventHandler(exit_fileExact);
                            process.Start();

                            while (!flag)
                            {
                                System.Threading.Thread.Sleep(500);
                            }
                            flag = false;

                            process = new Process();
                            process.StartInfo.FileName = "adb.exe";
                            process.StartInfo.UseShellExecute = false;
                            //process.StartInfo.RedirectStandardOutput = true;
                            process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
                            process.StartInfo.CreateNoWindow = true;
                            process.EnableRaisingEvents = true;
                            process.StartInfo.Arguments = " pull /sdcard/13.img";
                            process.Exited += new EventHandler(exit_fileExact);
                            process.Start();

                            while (!flag)
                            {
                                System.Threading.Thread.Sleep(500);
                            }
                            flag = false;

                            
                            process = new Process();
                            process.StartInfo.FileName = "adb.exe";
                            process.StartInfo.UseShellExecute = false;
                            //process.StartInfo.RedirectStandardOutput = true;
                            process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
                            process.StartInfo.CreateNoWindow = true;
                            process.EnableRaisingEvents = true;
                            process.StartInfo.Arguments = " pull /sdcard/17.img";
                            process.Exited += new EventHandler(exit_fileExact);
                            process.Start();

                            while (!flag)
                            {
                                System.Threading.Thread.Sleep(500);
                            }
                            flag = false;

                            break;

                        case 2:
                            MessageBox.Show("외장메모리를 연결해주세요..");
                            
                            ProgressDialog.Report(bw, "디스크를 추출하는 중입니다..", i);
                            process = new Process();
                            process.StartInfo.FileName = "dd.exe";
                            process.StartInfo.UseShellExecute = false;
                            //process.StartInfo.RedirectStandardOutput = true;
                            process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
                            process.StartInfo.CreateNoWindow = true;
                            process.EnableRaisingEvents = true;
                            process.StartInfo.Arguments = " if=\\\\?\\Device\\Harddisk2\\Partition0 of=\\img\\usb.img bs=1M --size --progress";
                            process.Exited += new EventHandler(exit_fileExact);
                            process.Start();

                            while (!flag)
                            {
                                System.Threading.Thread.Sleep(500);
                            }
                            flag = false;

                            break;


                        case 3:
                            ProgressDialog.Report(bw, "디스크를 분석하는 중입니다..", i);
                            //fileOpen(saveFileDlg.FileName);
                            System.Threading.Thread.Sleep(500);
                            break;
                    }
                }

            }, ProgressDialogSettings.WithSubLabel);

            if (result.OperationFailed)
                MessageBox.Show("정보수집을 실패하였습니다.");
            else
                MessageBox.Show("정보수집을 성공하였습니다.");
        }

        private void RibbonButton_Start(object sender, RoutedEventArgs e)
        {
            getAllInformation();
        }

        private void RibbonButton_Save(object sender, RoutedEventArgs e)
        {
            saveInformation();
        }

        private void RibbonButton_Load(object sender, RoutedEventArgs e)
        {
            loadInformation();
        }

        private void MakeFilter()
        {
            if (curListType == LIST_TYPE.None||curListType == LIST_TYPE.GPSList)
            {
                FilterGrid.Children.Clear();
            }
            else
            {
                GroupBox groupBox = new GroupBox();
                groupBox.Margin = new Thickness(8, 0, 0, 0);

                RowDefinition rowDef;
                ColumnDefinition colDef;
                FilterGrid.Children.Clear();
                FilterGrid.RowDefinitions.Clear();
                FilterGrid.ColumnDefinitions.Clear();
                //index 0 column definition add            
                colDef = new ColumnDefinition();
                colDef.Width = new GridLength(1, GridUnitType.Auto);
                FilterGrid.ColumnDefinitions.Add(colDef);

                //index 0 row definition add
                rowDef = new RowDefinition();
                rowDef.Height = new GridLength(1, GridUnitType.Auto);
                FilterGrid.RowDefinitions.Add(rowDef);

                //'all column' checkbox add
                CheckBox allColCheckBox = new CheckBox();
                allColCheckBox.Content = "All Columns";
                allColCheckBox.Margin = new Thickness(8, 0, 0, 0);
                allColCheckBox.VerticalAlignment = System.Windows.VerticalAlignment.Center;

                groupBox.Header = allColCheckBox;
                Grid.SetRow(groupBox, 0);
                Grid.SetColumn(groupBox, 0);
                FilterGrid.Children.Add(groupBox);

                int j = DataGrid_User.Columns.Count;
                CheckBox colCheckBox;
                string colName;
                filterCheckBoxChildrenPanel = new StackPanel();

                for (int i = 0; i < j; i++)
                {
                    colName = DataGrid_User.Columns.ElementAt(i).Header.ToString();

                    colCheckBox = new CheckBox();                    
                    colCheckBox.Content = colName;
                    colCheckBox.Margin = new Thickness(8, 0, 0, 0);
                    colCheckBox.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    colCheckBox.IsEnabled = false;

                    filterCheckBoxChildrenPanel.Children.Add(colCheckBox);
                }

                groupBox.Content = filterCheckBoxChildrenPanel;
                allColCheckBox.IsChecked = true;
                filterCheckList = new Dictionary<string, bool>();
                filterCheckList.Add("all", true);
                
                allColCheckBox.Checked += new RoutedEventHandler(AllColumnCheckBox_Checked);
                allColCheckBox.Unchecked += new RoutedEventHandler(AllColumnMcCheckBox_Unchecked);               
            }
        }

        private void RefreshFilterCheckList()
        {
            bool tempBool = filterCheckList["all"];
            filterCheckList.Clear();
            filterCheckList.Add("all", tempBool);
            if (filterCheckBoxChildrenPanel != null)
            {
                foreach (var child in LogicalTreeHelper.GetChildren(filterCheckBoxChildrenPanel))
                {   //do something with child
                    CheckBox temp = (CheckBox)child;
                    filterCheckList.Add(temp.Content.ToString(), (bool)temp.IsChecked);
                }
            }
        }

        private void SearchUsingKeywords()
        {
            RefreshFilterCheckList();
            string keyword = SearchTextBox.GetLineText(0);
            if (curListType != LIST_TYPE.None)
            {
                switch (curListType)
                {
                    case LIST_TYPE.PhoneBookList:
                        SearchPhoneBookData(keyword);
                        break;
                    case LIST_TYPE.CallList:
                        SearchCallLogData(keyword);
                        break;
                    case LIST_TYPE.SmsList:
                        SearchSMSData(keyword);
                        break;
                    case LIST_TYPE.MmsList:
                        SearchMMSData(keyword);
                        break;
                    case LIST_TYPE.BookmarkList:
                        SearchBookmarksData(keyword);
                        break;
                    case LIST_TYPE.CalendarList:
                        SearchCalendarData(keyword);
                        break;
                    case LIST_TYPE.SearchList:
                        SearchSearchData(keyword);
                        break;
                    case LIST_TYPE.MapSearchList:
                        SearchMapSearchData(keyword);
                        break;
                    case LIST_TYPE.WifiList:
                        SearchWifiData(keyword);
                        break;
                    case LIST_TYPE.FacebookFriendsList:
                        SearchFacebookFriendsData(keyword);
                        break;
                    case LIST_TYPE.KakaotalkFriendsList:
                        SearchKakaotalkFriendsData(keyword);
                        break;
                    case LIST_TYPE.SeoulbusList:
                        SearchSeoulbusBusData(keyword);
                        break;
                    case LIST_TYPE.FacebookPhotoList:
                        SearchFacebookPhotosData(keyword);
                        break;
                    case LIST_TYPE.FacebookNotificationList:
                        SearchFacebookNotificationData(keyword);
                        break;
                    case LIST_TYPE.KakaotalkChatroomsList:
                        SearchKakaotalkChatroomsData(keyword);
                        break;
                    default:
                        break;

                }
            }
        }

        private void SearchPhoneBookData(string input)
        {
            //textbox에서 일단 text를 받아온다.
            //button click event 받는 function이랑 연결해 놓는다.

            String searchStr = input;
            int cnt = currentInfo.phoneList.data.Count;
            //data가 없으면 pass
            if (cnt <= 0)
            {
                MessageBox.Show("주소록 data가 없습니다.");
                return;

            }
            else
            {
                List<PhoneBookDataObject> tempList = new List<PhoneBookDataObject>();
                if (filterCheckList["all"])
                {
                    foreach (PhoneBookDataObject data in currentInfo.phoneList.data)
                    {
                        if (data.Name.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.PhoneNumber.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.HasNumber.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.Email.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.ContactStatus.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.InVisibleGroup.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.Starred.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.LastTimeContacted.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }
                else {
                    foreach (PhoneBookDataObject data in currentInfo.phoneList.data)
                    {
                        if (filterCheckList["Name"] && data.Name.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["PhoneNumber"] && data.PhoneNumber.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["HasNumber"] && data.HasNumber.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["Email"] && data.Email.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["ContactStatus"] && data.ContactStatus.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["InVisibleGroup"] && data.InVisibleGroup.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["Starred"] && data.Starred.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["LastTimeContacted"] && data.LastTimeContacted.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }
                
                DataGrid_User.ItemsSource = tempList;
            }
        }
        private void SearchSMSData(string input)
        {
            //textbox에서 일단 text를 받아온다.
            //button click event 받는 function이랑 연결해 놓는다.

            String searchStr = input;
            int cnt = currentInfo.smsList.data.Count;
            //data가 없으면 pass
            if (cnt <= 0)
            {
                MessageBox.Show("sms data가 없습니다.");
                return;

            }
            else
            {
                List<SMSDataObject> tempList = new List<SMSDataObject>();
                if (filterCheckList["all"])
                {
                    foreach (SMSDataObject data in currentInfo.smsList.data)
                    {
                        if (data.PhoneNumber.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.Date.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.Locked.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.Read.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.Type.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.Body.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }
                else {
                    foreach (SMSDataObject data in currentInfo.smsList.data)
                    {
                        if (filterCheckList["PhoneNumber"] && data.PhoneNumber.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["Date"] && data.Date.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["Locked"] && data.Locked.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["Read"] && data.Read.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["Type"] && data.Type.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["Body"] && data.Body.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                
                }              

                DataGrid_User.ItemsSource = tempList;
            }
        }
        private void SearchMMSData(string input)
        {
            //textbox에서 일단 text를 받아온다.
            //button click event 받는 function이랑 연결해 놓는다.

            String searchStr = input;
            int cnt = currentInfo.mmsList.data.Count;
            //data가 없으면 pass
            if (cnt <= 0)
            {
                MessageBox.Show("mms data가 없습니다.");
                return;

            }
            else
            {
                List<MMSDataObject> tempList = new List<MMSDataObject>();
                if (filterCheckList["all"])
                {
                    foreach (MMSDataObject data in currentInfo.mmsList.data)
                    {
                        if (data.PhoneNumber.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                            
                        }
                        else if (data.Date.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }                        
                        else if (data.Body.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.AttachedFile.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.DataType.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.Read.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.Type.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.Locked.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.MsgId.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }
                else {

                    foreach (MMSDataObject data in currentInfo.mmsList.data)
                    {
                        if (filterCheckList["PhoneNumber"] && data.PhoneNumber.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;

                        }
                        else if (filterCheckList["Date"] && data.Date.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["Body"] && data.Body.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["AttachedFile"] && data.AttachedFile.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["DataType"] && data.DataType.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["Read"] && data.Read.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["Type"] && data.Type.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["Locked"] && data.Locked.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["MsgId"] && data.MsgId.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                                      
                }
                
                DataGrid_User.ItemsSource = tempList;
            }
        }
        private void SearchCallLogData(string input)
        {
            //textbox에서 일단 text를 받아온다.
            //button click event 받는 function이랑 연결해 놓는다.

            String searchStr = input;
            int cnt = currentInfo.callList.data.Count;
            //data가 없으면 pass
            if (cnt <= 0)
            {
                MessageBox.Show("callLog data가 없습니다.");
                return;

            }
            else
            {
                List<CallDataObject> tempList = new List<CallDataObject>();
                if (filterCheckList["all"])
                {
                    foreach (CallDataObject data in currentInfo.callList.data)
                    {
                        if (data.PhoneNumber.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.Date.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.Name.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.Duration.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.Type.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }
                else {

                    foreach (CallDataObject data in currentInfo.callList.data)
                    {
                        if (filterCheckList["PhoneNumber"] && data.PhoneNumber.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["Date"] && data.Date.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["Name"] && data.Name.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["Duration"] && data.Duration.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["Type"] && data.Type.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                
                }
                
                DataGrid_User.ItemsSource = tempList;
            }
        }
        private void SearchBookmarksData(string input)
        {
            //textbox에서 일단 text를 받아온다.
            //button click event 받는 function이랑 연결해 놓는다.

            String searchStr = input;
            int cnt = currentInfo.bookmarkList.data.Count;
            //data가 없으면 pass
            if (cnt <= 0)
            {
                MessageBox.Show("bookmarks data가 없습니다.");
                return;

            }
            else
            {
                List<BookMarksDataObject> tempList = new List<BookMarksDataObject>();
                if (filterCheckList["all"])
                {

                    foreach (BookMarksDataObject data in currentInfo.bookmarkList.data)
                    {

                        if (data.Title.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.Url.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.Date.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.BookMark.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.CreatedDate.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.ID.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.UserEntered.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.Visits.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }

                }
                else {
                    foreach (BookMarksDataObject data in currentInfo.bookmarkList.data)
                    {

                        if (filterCheckList["Title"] && data.Title.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["Url"] && data.Url.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["Date"] && data.Date.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["BookMark"] && data.BookMark.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["CreatedDate"] && data.CreatedDate.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["ID"] && data.ID.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["UserEntered"] && data.UserEntered.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["Visits"] && data.Visits.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }                
                }
               
                DataGrid_User.ItemsSource = tempList;
            }
        }
        private void SearchCalendarData(string input)
        {
            //textbox에서 일단 text를 받아온다.
            //button click event 받는 function이랑 연결해 놓는다.

            String searchStr = input;
            int cnt = currentInfo.calendarList.data.Count;
            //data가 없으면 pass
            if (cnt <= 0)
            {
                MessageBox.Show("calendar data가 없습니다.");
                return;

            }
            else
            {
                List<CalendarDataObject> tempList = new List<CalendarDataObject>();
                if (filterCheckList["all"])
                {

                    foreach (CalendarDataObject data in currentInfo.calendarList.data)
                    {
                        if (data.Title.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.EventLocation.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.Description.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.DateStart.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.DateEnd.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.ID.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }
                else {

                    foreach (CalendarDataObject data in currentInfo.calendarList.data)
                    {
                        if (filterCheckList["Title"] && data.Title.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["EventLocation"] && data.EventLocation.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["Description"] && data.Description.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["DateStart"] && data.DateStart.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["DateEnd"] && data.DateEnd.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["ID"] && data.ID.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                
                }
                
                DataGrid_User.ItemsSource = tempList;
            }
        }
        private void SearchSearchData(string input)
        {
            //textbox에서 일단 text를 받아온다.
            //button click event 받는 function이랑 연결해 놓는다.

            String searchStr = input;
            int cnt = currentInfo.searchDataList.data.Count;
            //data가 없으면 pass
            if (cnt <= 0)
            {
                MessageBox.Show("search data가 없습니다.");
                return;

            }
            else
            {
                List<SearchesDataObject> tempList = new List<SearchesDataObject>();
                if (filterCheckList["all"])
                {
                    foreach (SearchesDataObject data in currentInfo.searchDataList.data)
                    {
                        if (data.Search.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.Date.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.ID.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }
                else {
                    foreach (SearchesDataObject data in currentInfo.searchDataList.data)
                    {
                        if (filterCheckList["Search"] && data.Search.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["Date"] && data.Date.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["ID"] && data.ID.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }
                
                DataGrid_User.ItemsSource = tempList;
            }
        }        
        private void SearchMapSearchData(string input)
        {
            //textbox에서 일단 text를 받아온다.
            //button click event 받는 function이랑 연결해 놓는다.
            //currentInfo.mapSearchHistoryLoader.
            
            String searchStr = input;
            int cnt = currentInfo.mapSearchHistoryLoader.searchList.Count;
            //data가 없으면 pass
            if (cnt <= 0)
            {
                MessageBox.Show("map search data가 없습니다.");
                return;

            }
            else
            {
                List<ApplicationLoader.MapSearchHistory.MapSearch> tempList = new List<ApplicationLoader.MapSearchHistory.MapSearch>();
                if (filterCheckList["all"])
                {
                    foreach (ApplicationLoader.MapSearchHistory.MapSearch data in currentInfo.mapSearchHistoryLoader.searchList)
                    {                        
                        if (data.searchStr.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.latitude.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.longitude.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }
                else
                {
                    foreach (ApplicationLoader.MapSearchHistory.MapSearch data in currentInfo.mapSearchHistoryLoader.searchList)
                    {
                        if (filterCheckList["searchStr"] && data.searchStr.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["latitude"] && data.latitude.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["longitude"] && data.longitude.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }

                DataGrid_User.ItemsSource = tempList;
            }
        }
        private void SearchWifiData(string input)
        {
            //textbox에서 일단 text를 받아온다.
            //button click event 받는 function이랑 연결해 놓는다.            

            String searchStr = input;
            int cnt = currentInfo.deviceInformation.wifiInformation.wifiHistoryList.Count;
            //currentInfo.deviceInformation.wifiInformation.
            //data가 없으면 pass
            if (cnt <= 0)
            {
                MessageBox.Show("wifi data가 없습니다.");
                return;

            }
            else
            {
                List<WifiInformation.WifiHistory> tempList = new List<WifiInformation.WifiHistory>();
                if (filterCheckList["all"])
                {
                    foreach (WifiInformation.WifiHistory data in currentInfo.deviceInformation.wifiInformation.wifiHistoryList)
                    {
                        
                        if (data.auth_alg.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.key_mgmt.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.priority.ToString().Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.proto.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.psk.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.ssid.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }
                else
                {
                    foreach (WifiInformation.WifiHistory data in currentInfo.deviceInformation.wifiInformation.wifiHistoryList)
                    {

                        if (filterCheckList["auth_alg"] && data.auth_alg.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["key_mgmt"] && data.key_mgmt.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["priority"] && data.priority.ToString().Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["proto"] && data.proto.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["psk"] && data.psk.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["ssid"] && data.ssid.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }

                DataGrid_User.ItemsSource = tempList;
            }
        }
        private void SearchFacebookFriendsData(string input)
        {
            //textbox에서 일단 text를 받아온다.
            //button click event 받는 function이랑 연결해 놓는다.
            //currentInfo.mapSearchHistoryLoader.

            String searchStr = input;
            int cnt = currentInfo.facebookLoader.friendsList.Count;            
            //data가 없으면 pass
            if (cnt <= 0)
            {
                MessageBox.Show("facebook friends data가 없습니다.");
                return;

            }
            else
            {
                List<ApplicationLoader.Facebook.Friends> tempList = new List<ApplicationLoader.Facebook.Friends>();
                if (filterCheckList["all"])
                {
                    foreach (ApplicationLoader.Facebook.Friends data in currentInfo.facebookLoader.friendsList)
                    {                        
                        if (data.name.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.email.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.cell.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                            else if (data.birthday_year.ToString().Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                            else if (data.birthday_month.ToString().Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                            else if (data.birthday_day.ToString().Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }
                else
                {
                    foreach (ApplicationLoader.Facebook.Friends data in currentInfo.facebookLoader.friendsList)
                    {
                        if (filterCheckList["name"] && data.name.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["email"] && data.email.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["cell"] && data.cell.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["birthday_year"] && data.birthday_year.ToString().Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["birthday_month"] && data.birthday_month.ToString().Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["birthday_day"] && data.birthday_day.ToString().Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }

                DataGrid_User.ItemsSource = tempList;
            }
        }
        private void SearchKakaotalkFriendsData(string input)
        {
            //textbox에서 일단 text를 받아온다.
            //button click event 받는 function이랑 연결해 놓는다.
            //currentInfo.mapSearchHistoryLoader.

            String searchStr = input;
            int cnt = currentInfo.kakaoTalkLoader.friendsList.Count;            
            //data가 없으면 pass
            if (cnt <= 0)
            {
                MessageBox.Show("kakaotalk friends data가 없습니다.");
                return;

            }
            else
            {
                List<ApplicationLoader.KaKaoTalk.Friends> tempList = new List<ApplicationLoader.KaKaoTalk.Friends>();
                if (filterCheckList["all"])
                {
                    foreach (ApplicationLoader.KaKaoTalk.Friends data in currentInfo.kakaoTalkLoader.friendsList)
                    {
                        
                        if (data.name.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.contact_name.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.phone_number.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.status_message.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.type.ToString().Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.uuid.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }
                else
                {
                    foreach (ApplicationLoader.KaKaoTalk.Friends data in currentInfo.kakaoTalkLoader.friendsList)
                    {

                        if (filterCheckList["name"] && data.name.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["contact_name"] && data.contact_name.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["phone_number"] && data.phone_number.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["status_message"] && data.status_message.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["type"] && data.type.ToString().Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["uuid"] && data.uuid.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }

                DataGrid_User.ItemsSource = tempList;
            }
        }
        private void SearchSeoulbusBusData(string input)
        {
            //textbox에서 일단 text를 받아온다.
            //button click event 받는 function이랑 연결해 놓는다.
            //currentInfo.mapSearchHistoryLoader.

            String searchStr = input;
            int cnt = currentInfo.seoulBusLoader.recentBusList.Count;            
            //data가 없으면 pass
            if (cnt <= 0)
            {
                MessageBox.Show("seoulbus bus data가 없습니다.");
                return;

            }
            else
            {
                List<ApplicationLoader.SeoulBus.RecentBus> tempList = new List<ApplicationLoader.SeoulBus.RecentBus>();
                if (filterCheckList["all"])
                {
                    foreach (ApplicationLoader.SeoulBus.RecentBus data in currentInfo.seoulBusLoader.recentBusList)
                    {
                        if (data.number.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.region.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.time.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.type.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }                       
                        else
                        {
                            //do nothing
                        }
                    }
                }
                else
                {
                    foreach (ApplicationLoader.SeoulBus.RecentBus data in currentInfo.seoulBusLoader.recentBusList)
                    {
                        if (filterCheckList["number"] && data.number.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["region"] && data.region.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["time"] && data.time.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["type"] && data.type.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }

                DataGrid_User.ItemsSource = tempList;
            }
        }
        private void SearchFacebookPhotosData(string input)
        {
            //textbox에서 일단 text를 받아온다.
            //button click event 받는 function이랑 연결해 놓는다.
                       
            String searchStr = input;
            int cnt = currentInfo.facebookLoader.photosList.Count;
            
            //data가 없으면 pass
            if (cnt <= 0)
            {
                MessageBox.Show("facebook photos data가 없습니다.");
                return;

            }
            else
            {
                List<ApplicationLoader.Facebook.Photos> tempList = new List<ApplicationLoader.Facebook.Photos>();
                if (filterCheckList["all"])
                {
                    foreach (ApplicationLoader.Facebook.Photos data in currentInfo.facebookLoader.photosList)
                    {                        
                        if (data.caption.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.name.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.created.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.url.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }
                else
                {
                    foreach (ApplicationLoader.Facebook.Photos data in currentInfo.facebookLoader.photosList)
                    {
                        if (filterCheckList["caption"] && data.caption.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["name"] && data.name.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["created"] && data.created.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["url"] && data.url.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }

                DataGrid_User.ItemsSource = tempList;
            }
        }
        private void SearchFacebookNotificationData(string input)
        {
            //textbox에서 일단 text를 받아온다.
            //button click event 받는 function이랑 연결해 놓는다.
                        
            String searchStr = input;
            int cnt = currentInfo.facebookLoader.notificationsList.Count;
            
            //data가 없으면 pass
            if (cnt <= 0)
            {
                MessageBox.Show("facebook notification data가 없습니다.");
                return;

            }
            else
            {
                List<ApplicationLoader.Facebook.Notifications> tempList = new List<ApplicationLoader.Facebook.Notifications>();
                if (filterCheckList["all"])
                {
                    foreach (ApplicationLoader.Facebook.Notifications data in currentInfo.facebookLoader.notificationsList)
                    {                       
                        if (data.title.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.sender_name.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.updated.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }
                else
                {
                    foreach (ApplicationLoader.Facebook.Notifications data in currentInfo.facebookLoader.notificationsList)
                    {
                        if (filterCheckList["title"] && data.title.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["sender_name"] && data.sender_name.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["updated"] && data.updated.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }

                DataGrid_User.ItemsSource = tempList;
            }
        }
        private void SearchKakaotalkChatroomsData(string input)
        {
            //textbox에서 일단 text를 받아온다.
            //button click event 받는 function이랑 연결해 놓는다.
                        
            String searchStr = input;
            int cnt = currentInfo.kakaoTalkLoader.chatRoomsList.Count;             
            
            //data가 없으면 pass
            if (cnt <= 0)
            {
                MessageBox.Show("kakaotalk chatrooms data가 없습니다.");
                return;

            }
            else
            {
                List<ApplicationLoader.KaKaoTalk.chatRooms> tempList = new List<ApplicationLoader.KaKaoTalk.chatRooms>();
                if (filterCheckList["all"])
                {
                    foreach (ApplicationLoader.KaKaoTalk.chatRooms data in currentInfo.kakaoTalkLoader.chatRoomsList)
                    {                        
                        if (data.member.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.last_message.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.last_update.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.chat_id.ToString().Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (data.type.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }
                else
                {
                    foreach (ApplicationLoader.KaKaoTalk.chatRooms data in currentInfo.kakaoTalkLoader.chatRoomsList)
                    {
                        if (filterCheckList["member"] && data.member.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["last_message"] && data.last_message.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["last_update"] && data.last_update.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["chat_id"] && data.chat_id.ToString().Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else if (filterCheckList["type"] && data.type.Contains(searchStr))
                        {
                            tempList.Add(data);
                            continue;
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }

                DataGrid_User.ItemsSource = tempList;
            }
        }

        bool flag = false;
        public void exit_fileExact(object sender, System.EventArgs e)
        {
            flag = true;
        }



        
        
        public void fileOpen(string fileName)
        {
            FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite);
            BinaryReader br = new BinaryReader(fs);
            long i = 0;
            int j = 0;
            string temp = "";

            byte[] byteArray = new byte[16];

            //System.Threading.Tasks.Parallel.For(0, fs.Length, (k, i) =>
            for (long k = 0; k < fs.Length; k++)
            {
                byte tempByte = br.ReadByte();
                temp += String.Format("{0:X2} ", tempByte);
                byteArray[i] = (tempByte > 31 && tempByte < 126) ? tempByte : (byte)46;
                i++;

                if (i == 15)
                {
                    offsetBox.Text += (String.Format("{0:00000000}:  ", (int)(j * 16)));
                    offsetBox.Text += (temp + "  ");
                    ASCIIEncoding ascii = new ASCIIEncoding();
                    string decoding = ascii.GetString(byteArray);

                    offsetBox.Text += (decoding + "\n");
                    
                    
                    /*
                    fuck += (String.Format("{0:00000000}:  ", (int)(j * 16)));
                    fuck += (temp + "  ");
                    ASCIIEncoding ascii = new ASCIIEncoding();
                    string decoding = ascii.GetString(byteArray);
                    fuck += (decoding + "\n");
                    */
                    temp = "";

                    i = 0;
                    j++;

                }
            }
            fs.Close();
        }

        /*
        public void fileOpen(string fileName)
        {
            FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite);
            BinaryReader br = new BinaryReader(fs);

            byte[] byteArray = new byte[16];

            System.Threading.Tasks.Parallel.For(0, fs.Length / 16, (k) =>
            //for ( long k = 0; k < fs.Length; k+=16 )
            {
                offsetBox.Text += (String.Format("{0:00000000}:  ", (int)(k*16)));
                br.Read(byteArray, 0, 16);
                offsetBox.Text += String.Format("{0:X2} {1:X2} {2:X2} {3:X2} {4:X2} {5:X2} {6:X2} {7:X2} {8:X2} {9:X2} {10:X2} {11:X2} {12:X2} {13:X2} {14:X2} {15:X2}",
                      byteArray[0]
                    , byteArray[1]
                    , byteArray[2]
                    , byteArray[3]
                    , byteArray[4]
                    , byteArray[5]
                    , byteArray[6]
                    , byteArray[7]
                    , byteArray[8]
                    , byteArray[9]
                    , byteArray[10]
                    , byteArray[11]
                    , byteArray[12]
                    , byteArray[13]
                    , byteArray[14]
                    , byteArray[15]
                    );
                / *
                for (int z = 0; z < 16; z++)
                {
                    byteArray[z] = (byteArray[z] > 31 && byteArray[z] < 126) ? byteArray[z] : (byte)46;
                }

                ASCIIEncoding ascii = new ASCIIEncoding();
                string decoding = ascii.GetString(byteArray);
                offsetBox.Text += (decoding + "\n");
                * /
                offsetBox.Text += "\n";

            });
            fs.Close();
            //offsetBox.Text = fuck;
        }
        */
        public void getAllInformation()
        {

            currentInfo.deviceInformation = new AFT2.DeviceInformationLoader();

            ProgressDialogResult result = ProgressDialog.Execute(this, "Loading data", (bw) =>
            {
                for (int i = 1; i <= 5; i++)
                {
                    switch (i)
                    {
                        case 1:
                            ProgressDialog.Report(bw, "ADB 접속을 확인하는 중입니다..{0}/5", i);
                            //Adb 접속 확인.
                            Process[] adbConnection = Process.GetProcessesByName("adb");
                            if (adbConnection.Length == 0)
                            {
                                if (currentInfo.deviceInformation.runADB() == 0)
                                {
                                    MessageBox.Show("휴대폰이 연결되지 않았습니다.");
                                    return;
                                }
                            }
                            else
                            {
                                if (currentInfo.deviceInformation.checkADB() == 0)
                                {
                                    MessageBox.Show("휴대폰이 연결되지 않았습니다.");
                                    return;
                                }
                            }


                            System.Threading.Thread.Sleep(700);
                            break;
                        case 2:
                            ProgressDialog.Report(bw, "디바이스 정보를 추출하는 중입니다..{0}/5", i);
                            currentInfo.deviceInformation.installApp();
                            currentInfo.deviceInformation.startApp();
                            while (currentInfo.deviceInformation.checkPS() == 0)
                            {
                                System.Threading.Thread.Sleep(3000);
                            }
                            currentInfo.deviceInformation.uninstallApp();
                            break;
                        case 3:
                            ProgressDialog.Report(bw, "어플리케이션 정보를 추출하는 중입니다..{0}/5", i);
                            currentInfo.deviceInformation.runADB("", "adb.exe", "pull /mnt/sdcard/phoneData.db ./db/phoneData.db");
                            currentInfo.deviceInformation.runADB("", "adb.exe", "pull /data/data/com.facebook.katana/databases/fb.db ./db/fb.db");
                            currentInfo.deviceInformation.runADB("", "adb.exe", "pull /data/data/com.astroframe.seoulbus/databases/recent.sqlite ./db/seoulbus.db");
                            currentInfo.deviceInformation.runADB("", "adb.exe", "pull /data/data/com.kakao.talk/databases/KakaoTalk.db ./db/KakaoTalk.db");
                            currentInfo.deviceInformation.runADB("", "adb.exe", "pull /data/data/com.google.android.apps.maps/databases/search_history.db ./db/search_history.db");
                            currentInfo.deviceInformation.runADB("", "adb.exe", "pull /data/data/com.android.browser/app_geolocation/CachedGeoposition.db ./db/CachedGeoposition.db");
                            while (currentInfo.deviceInformation.num != 6)
                                System.Threading.Thread.Sleep(500);
                            break;
                        case 4:
                            ProgressDialog.Report(bw, "추출된 정보를 분석하는 중입니다..{0}/5", i);
                            currentInfo.deviceInformation.getDeviceInformation();
                            currentInfo.kakaoTalkLoader = new ApplicationLoader.KaKaoTalk();
                            currentInfo.facebookLoader = new ApplicationLoader.Facebook();
                            currentInfo.seoulBusLoader = new ApplicationLoader.SeoulBus();
                            currentInfo.mapSearchHistoryLoader = new ApplicationLoader.MapSearchHistory();
                            currentInfo.gpsHistory = new ApplicationLoader.GPSHistory();
                            //어플 설치하고 실행
                            //어플 끝날때까지 대기
                            //Sdcard데이터 폴더로 가져오기

                            currentInfo.callList = new CallDataList();
                            currentInfo.mmsList = new MMSDataList();
                            currentInfo.phoneList = new PhoneBookDataList();
                            currentInfo.calendarList = new CalendarDataList();
                            currentInfo.bookmarkList = new BookMarksDataList();
                            currentInfo.searchDataList = new SearchesDataList();
                            currentInfo.smsList = new SMSDataList();
                            break;
                        case 5:
                            ProgressDialog.Report(bw, "작업을 완료하는 중입니다..{0}/5", i);
                            System.Threading.Thread.Sleep(500);
                            break;
                    }


                }

            }, ProgressDialogSettings.WithSubLabel);

            if (result.OperationFailed)
                MessageBox.Show("정보수집을 실패하였습니다.");
            else
                MessageBox.Show("정보수집을 성공하였습니다.");


            printDeviceInformation();
           


        }

        class DeviceInformationForPrint {
            public DeviceInformationForPrint(string _item, string _value) {
                Item = _item;
                Value = _value;
            }
            public string Item { get; set; }
            public string Value { get; set; }
        }

        private void printDeviceInformation()
        {
            List<DeviceInformationForPrint> list = new List<DeviceInformationForPrint>();

            list.Add(new DeviceInformationForPrint("Boot Loader", currentInfo.deviceInformation.bootLoader));
            list.Add(new DeviceInformationForPrint("Build Version", currentInfo.deviceInformation.buildVersion));
            list.Add(new DeviceInformationForPrint("Kernel Version", currentInfo.deviceInformation.kernelVersion));
            list.Add(new DeviceInformationForPrint("Uptime", currentInfo.deviceInformation.uptime));
            list.Add(new DeviceInformationForPrint("Serial", currentInfo.deviceInformation.serial));
            list.Add(new DeviceInformationForPrint("Network", currentInfo.deviceInformation.network));
            list.Add(new DeviceInformationForPrint("Model Name", currentInfo.deviceInformation.modelName));


            list.Add(new DeviceInformationForPrint("주소록", currentInfo.phoneList.data.Count+"개"));
            list.Add(new DeviceInformationForPrint("전화기록", currentInfo.callList.data.Count + "개"));
            list.Add(new DeviceInformationForPrint("SMS", currentInfo.smsList.data.Count + "개"));
            list.Add(new DeviceInformationForPrint("MMS", currentInfo.mmsList.data.Count + "개"));
            list.Add(new DeviceInformationForPrint("Calender", currentInfo.calendarList.data.Count + "개"));
            list.Add(new DeviceInformationForPrint("GPS", currentInfo.gpsHistory.gpsList.Count + "개"));
            list.Add(new DeviceInformationForPrint("WIFI", currentInfo.deviceInformation.wifiInformation.wifiHistoryList.Count + "개"));
            list.Add(new DeviceInformationForPrint("Search", currentInfo.searchDataList.data.Count.ToString()));
            list.Add(new DeviceInformationForPrint("Map Search", currentInfo.mapSearchHistoryLoader.searchList.Count + "개"));
            list.Add(new DeviceInformationForPrint("Browser", currentInfo.bookmarkList.data.Count + "개"));
            list.Add(new DeviceInformationForPrint("Facebook 친구", currentInfo.facebookLoader.friendsList.Count + "명"));
            list.Add(new DeviceInformationForPrint("Facebook 사진", currentInfo.facebookLoader.photosList.Count + "개"));
            list.Add(new DeviceInformationForPrint("Facebook 알림", currentInfo.facebookLoader.notificationsList.Count + "개"));
            list.Add(new DeviceInformationForPrint("SeoulBus 검색", currentInfo.seoulBusLoader.recentBusList.Count + "개"));
            list.Add(new DeviceInformationForPrint("카카오톡 친구", currentInfo.kakaoTalkLoader.friendsList.Count + "명"));
            list.Add(new DeviceInformationForPrint("카카오톡 채팅방", currentInfo.kakaoTalkLoader.chatRoomsList.Count + "개"));
            list.Add(new DeviceInformationForPrint("카카오톡 채팅", currentInfo.kakaoTalkLoader.num + "개"));
            DataGrid_Info.ItemsSource = list;
            RibbonInfoBtn.IsEnabled = true;
            DataGrid_System.ItemsSource = currentInfo.deviceInformation.diskInformation.diskInfomation;       
        }

        public void saveInformation()
        {
            Microsoft.Win32.SaveFileDialog saveFileDlg = new Microsoft.Win32.SaveFileDialog();
            //존재하지 않는 파일이 지정된 경우 SaveFileDlg에서 파일을 새로 만들지 묻는 메세지를 표시를 여부
            saveFileDlg.CreatePrompt = true;
            // 이미 존재하는 파일이 지정된 경우Save FileDlg에서 경고를 포시할지 여부를 나타내는 값을 가져오거나 설정
            saveFileDlg.OverwritePrompt = true;
            // 파일명
            saveFileDlg.FileName = "forensicdata";
            // 필터
            saveFileDlg.Filter = "Android Forensic Information(*.aft)|*.aft";
            // 기본 저장경로
            //saveFileDlg.InitialDirectory = @"c:\";
            Nullable<bool> re = saveFileDlg.ShowDialog();
            if (re.HasValue && re.Value)
            {
                try
                {
                    IFormatter formatter = new BinaryFormatter();
                    Stream streamWrite = new FileStream(
                        saveFileDlg.FileName,
                        FileMode.Create,
                        FileAccess.Write,
                        FileShare.None);
                    formatter.Serialize(streamWrite, currentInfo);
                    streamWrite.Close();

                }
                catch (Exception)
                {
                    throw;
                }
            }

        }

        public void loadInformation()
        {
            Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
            openFileDialog.Multiselect = false;
            openFileDialog.Filter = "Android Forensic Information(*.aft)|*.aft";
            Nullable<bool> re = openFileDialog.ShowDialog();
            if (re.HasValue && re.Value)
            {
                try
                {
                    IFormatter formatter = new BinaryFormatter();
                    Stream streamRead = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.None);
                    currentInfo = (CurrentInformation)formatter.Deserialize(streamRead);
                    streamRead.Close();

                }
                catch (Exception)
                {
                    throw;
                }
            }
            printDeviceInformation();
            /*
            IFormatter formatter = new BinaryFormatter();
            Stream streamRead = new FileStream("asdf.bin", FileMode.Open, FileAccess.Read, FileShare.None);
            currentInfo = (CurrentInformation)formatter.Deserialize(streamRead);
            streamRead.Close();
            */
        }

        private void Ribbon_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {

        }

        private void SearchBtn_Click(object sender, RoutedEventArgs e)
        {
            SearchUsingKeywords();
        }

        private void AllColumnCheckBox_Checked(object sender, RoutedEventArgs e)
        {
            filterCheckList["all"] = true;
            if (filterCheckBoxChildrenPanel.Children.Count == 0)
            {
            }
            else
            {
                foreach (var child in LogicalTreeHelper.GetChildren(filterCheckBoxChildrenPanel))
                {
                    //do something with child
                    CheckBox temp = (CheckBox)child;
                    temp.IsEnabled = false;
                }

            };

        }

        private void AllColumnMcCheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            filterCheckList["all"] = false;
            if (filterCheckBoxChildrenPanel.Children.Count == 0)
            {
            }
            else
            {
                foreach (var child in LogicalTreeHelper.GetChildren(filterCheckBoxChildrenPanel))
                {
                    //do something with child
                    CheckBox temp = (CheckBox)child;
                    temp.IsEnabled = true;
                }

            };

        }

        public void NewWebBrowser()
        {
            string baseStr = "file://127.0.0.1/";
            string mapHtmlName = "MapBinding.htm";
            string[] param = { "\\" };
            string[] strList = AppDomain.CurrentDomain.BaseDirectory.Split(param, StringSplitOptions.RemoveEmptyEntries);
            int j = strList.Length;
            for (int i = 0; i < j; i++)
            {

                if (i == 0)
                {
                    string temp = strList[i].Replace(":", "$");
                    baseStr += temp + "/";
                    continue;
                }

                if (strList[i] == "bin")
                {
                    break;
                }
                else
                {
                    baseStr += strList[i] + "/";

                }
            }

            baseStr += mapHtmlName;
            //Process.Start(url);            

            if (anotherWindow == null)
            {
                anotherWindow = new Window();
                anotherWindow.Width = 500;
                anotherWindow.Height = 300;
                anotherWindow.Closed += new EventHandler(WebWindow_Close);
                myWeb = new WebBrowser();
                myWeb.Name = "myBrowser";
                myWeb.Width = 500;
                myWeb.Height = 300;
                anotherWindow.Content = myWeb;
                anotherWindow.Show();
                myWeb.Navigate(baseStr);
            }
        }
        Window anotherWindow;
        WebBrowser myWeb;

        private void WebWindow_Close(object sender, EventArgs e)
        {
            if (anotherWindow != null)
            {
                anotherWindow = null;
                if (myWeb != null)
                {
                    myWeb = null;
                }

            }
        }

        public void ChangeMapLocationWithCoor(double x, double y)
        {
            if (anotherWindow != null)
            {
                if (myWeb != null)
                {
                    if (anotherWindow.IsLoaded)
                    {
                        myWeb.InvokeScript("panCoordinate", x, y);

                    }
                    else
                    {
                        MessageBox.Show("WebBrawser 준비중입니다.");
                    }
                }
            }
        }

        public void ChangeMapLocationWithAddr(string address)
        {
            if (anotherWindow != null)
            {
                if (myWeb != null)
                {
                    if (anotherWindow.IsLoaded)
                    {
                        myWeb.InvokeScript("codeAddress", address);

                    }
                    else
                    {
                        MessageBox.Show("WebBrawser 준비중입니다.");
                    }
                }
            }
        }

        private void DatagridUser_DoubleClick(object sender, RoutedEventArgs e)
        {
            DataGrid grid = (DataGrid)sender;
            if (curListType == LIST_TYPE.KakaotalkChatroomsList)
            {
                if (grid.SelectedItem != null)
                {
                    ApplicationLoader.KaKaoTalk.chatRooms temp = (ApplicationLoader.KaKaoTalk.chatRooms)grid.SelectedItem;
                    List<ApplicationLoader.KaKaoTalk.chatLogs> chatList = currentInfo.kakaoTalkLoader.chatLogsDic[temp.chat_id];
                    DataGrid_User.ItemsSource = chatList;
                    curListType = LIST_TYPE.KakaotalkChatlogList;
                    GroupBox gb = (GroupBox)FilterGrid.Children[0];
                    gb.IsEnabled = false;

                }
            }
            else if (curListType == LIST_TYPE.KakaotalkChatlogList)
            {

                DataGrid_User.ItemsSource = currentInfo.kakaoTalkLoader.chatRoomsList;
                curListType = LIST_TYPE.KakaotalkChatroomsList;
                GroupBox gb = (GroupBox)FilterGrid.Children[0];
                gb.IsEnabled = true;
            }
            else if (curListType == LIST_TYPE.GPSList)
            {
                if (grid.SelectedItem != null)
                {
                    if (anotherWindow == null)
                    {
                        NewWebBrowser();
                    }
                    else
                    {
                        ApplicationLoader.GPSHistory.GPS temp = (ApplicationLoader.GPSHistory.GPS)grid.SelectedItem;
                        if ((Convert.ToDouble(temp.latitude) <= 90 && Convert.ToDouble(temp.latitude) >= -90) && (Convert.ToDouble(temp.longitude) <= 180 && Convert.ToDouble(temp.longitude) >= -180))
                        {
                            ChangeMapLocationWithCoor(Convert.ToDouble(temp.latitude), Convert.ToDouble(temp.longitude));
                        }
                        else
                        {

                            MessageBox.Show("잘못된 좌표값입니다.");
                            //ChangeMapLocationWithAddr(temp.                    
                        }

                    }
                }
            }
            else if (curListType == LIST_TYPE.MapSearchList)
            {

                if (grid.SelectedItem != null)
                {
                    if (anotherWindow == null)
                    {
                        NewWebBrowser();
                    }
                    else
                    {

                        ApplicationLoader.MapSearchHistory.MapSearch temp = (ApplicationLoader.MapSearchHistory.MapSearch)grid.SelectedItem;
                        if ((Convert.ToDouble(temp.latitude) <= 90 && Convert.ToDouble(temp.latitude) >= -90) && (Convert.ToDouble(temp.longitude) <= 180 && Convert.ToDouble(temp.longitude) >= -180))
                        {
                            ChangeMapLocationWithCoor(Convert.ToDouble(temp.latitude), Convert.ToDouble(temp.longitude));
                        }
                        else if (temp.searchStr != null)
                        {

                            ChangeMapLocationWithAddr(temp.searchStr);
                        }
                        else
                        {
                            MessageBox.Show("잘못된 위치 좌표값입니다.");
                        }

                    }
                }

            }
        }


        private void RibbonButton_MemoryAnalysis(object sender, RoutedEventArgs e)
        {
            string[] files = System.IO.Directory.GetFiles("img");
            ListBox_ImageFiles.Items.Clear();
            foreach (string str in files)
            {

                Label temp = new Label();
                temp.Content = str.Split("\\".ToCharArray())[1];
                temp.MouseDoubleClick += new MouseButtonEventHandler(ListBox_ImageFiles_MouseDoubleClick);
                ListBox_ImageFiles.Items.Add(temp);
            }
        }

        private string currentSelectedImageFile;
        private string currentWorkingDirectory = null;

        void ListBox_ImageFiles_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            currentSelectedImageFile = "img\\" + ((Label)sender).Content.ToString();
            currentWorkingDirectory = null;
            refreshMemoryDataGrid("/");

            refreshImageInformation();
        }

        void refreshImageInformation()
        {
            /*
            Text_ImageFile.Text = currentSelectedImageFile.Split("\\".ToCharArray())[1];
            SleuthKit.DiskImage diskImg = new DiskImage(new FileInfo(currentSelectedImageFile));
            SleuthKit.FileSystem fileSystem = diskImg.OpenFileSystem();
            Text_SectorSize.Text = Convert.ToString(diskImg.SectorSize);
            Text_DiskSize.Text = Convert.ToString(diskImg.Size);
            if (fileSystem.TypeString == null)
            {
                Text_Type.Visibility = Visibility.Collapsed;
                Text_Type2.Visibility = Visibility.Collapsed;
            }
            else
            {
                Text_Type.Text = fileSystem.TypeString;
            }
            Text_BlockSize.Text = Convert.ToString(fileSystem.BlockSize);
            Text_BlockCount.Text = Convert.ToString(fileSystem.BlockCount);
            Text_ALastBlock.Text = Convert.ToString(fileSystem.ActualLastBlock);
            Text_FirstBlock.Text = Convert.ToString(fileSystem.FirstBlock);
            Text_LastBlock.Text = Convert.ToString(fileSystem.LastBlock);
            */
        }

        void refreshMemoryDataGrid(string dirName)
        {

            if (currentWorkingDirectory == null)
            {
                currentWorkingDirectory = "/";
            }
            else
            {
                currentWorkingDirectory += "/" + dirName;
            }

            DataGrid_Memory.Items.Clear();
            FileDataObject entry;
            try
            {
                //MessageBox.Show(currentSelectedImageFile + " -dir " + currentWorkingDirectory);

                Process process = new Process();
                process.StartInfo.FileName = "bin/tskmodule.exe";
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
                process.StartInfo.CreateNoWindow = true;
                process.EnableRaisingEvents = true;
                process.StartInfo.Arguments = " " + currentSelectedImageFile + " -dir " + currentWorkingDirectory;
                process.Start();

                while (!process.StandardOutput.EndOfStream)
                {
                    string line = process.StandardOutput.ReadLine();

                    if ((line.Split(";".ToCharArray())).Length != 9)
                    {
                        //MessageBox.Show(line);
                    }
                    else
                    {
                        entry = new FileDataObject(line.Split(";".ToCharArray()));
                        DataGrid_Memory.Items.Add(entry);
                    }
                }

            }
            catch (Exception e)
            {
                //MessageBox.Show("error : \n" + e.Message);
                //currentWorkingDirectory = null;
            }
        }

        void DataGrid_Memory_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            FileDataObject selected = (FileDataObject)(((DataGrid)sender).SelectedItem);

            switch ((ENUM_FILE_TYPE)selected.Type)
            {
                case ENUM_FILE_TYPE.FILE_TYPE_DIR:
                    refreshMemoryDataGrid(selected.Name);
                    break;

                case ENUM_FILE_TYPE.FILE_TYPE_REG:
                    exactFile(selected);
                    break;
            }

        }

        private void exactFile(FileDataObject file)
        {
            
            Microsoft.Win32.SaveFileDialog saveFileDlg = new Microsoft.Win32.SaveFileDialog();
            saveFileDlg.CreatePrompt = true;
            saveFileDlg.OverwritePrompt = true;
            saveFileDlg.FileName = file.Name;
            saveFileDlg.Filter = "All Files(*.*)|*.*";
            Nullable<bool> re = saveFileDlg.ShowDialog();
            if (re.HasValue && re.Value)
            {
                
            }
            
            ProgressDialogResult result = ProgressDialog.Execute(this, "Loading data", (bw) =>
            {
                for (int i = 1; i <= 2; i++)
                {
                    switch (i)
                    {
                        case 1:
                            
                            ProgressDialog.Report(bw, "파일을 추출하는 중입니다..", i);
                            Process process = new Process();
                            process.StartInfo.FileName = "bin/tskmodule.exe";
                            process.StartInfo.UseShellExecute = false;
                            //process.StartInfo.RedirectStandardOutput = true;
                            process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
                            process.StartInfo.CreateNoWindow = true;
                            process.EnableRaisingEvents = true;
                            process.StartInfo.Arguments = " " + currentSelectedImageFile + " -icat " + file.Address + " \"" + saveFileDlg.FileName + "\"";
                            process.Exited += new EventHandler(exit_fileExact);
                            process.Start();

                            while (!flag)
                            {
                                System.Threading.Thread.Sleep(500);
                            }
                            flag = false;
                            break;
                        case 2:
                            ProgressDialog.Report(bw, "파일을 분석하는 중입니다..", i);
                            //
                            //System.Threading.Thread.Sleep(500);
                            break;
                    }
                }

            }, ProgressDialogSettings.WithSubLabel);

            if (result.OperationFailed)
            {
                MessageBox.Show("파일분석을 실패하였습니다.");
            }
            else
            {
                if (MessageBox.Show("분석하시겠습니까?", "분석", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    fileOpen(saveFileDlg.FileName);
                    MessageBox.Show("파일분석을 성공하였습니다.");
                }
                else
                {
                    MessageBox.Show("파일추출을 성공하였습니다.");
                }
            }
        }
    } // END class MainWindow
} // END namespace
